﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace LCrs.Web.personeinfo
{
    /// <summary>
    /// GetP 的摘要说明
    /// </summary>
    public class GetP : IHttpHandler, IRequiresSessionState
    {
        LCrs.BLL.PersonInfo bll = new LCrs.BLL.PersonInfo();
        
        public void ProcessRequest(HttpContext context)
        {
            string ac = "";
            if (null != context.Request.Form["action"])
            {//获取前台传来的值  
                ac = context.Request.Form["action"].ToString().Trim();
            }
            else if (null != context.Request.QueryString["action"])
            {
                ac = context.Request.QueryString["action"].ToString().Trim();
            }
            if (ac == "query")
                Query(context);
            else if (ac == "querys")
                Querys(context);
            else if (ac == "queryone")
                QueryOne(context);
            else if (ac == "querysl")
                Querysl(context);
            else if (ac == "add")
                add(context);
            else if (ac == "modify")
                modify(context);
            else if (ac == "delete")
                delete(context);
            else if (ac == "deletes")
                deletes(context);
            else if (ac == "modifygx")
                modifygx(context);
            else if (ac == "import")
                importUser(context);
            else if (ac == "out")
                outUser(context);
            else if (ac == "outFP")
                outFP(context);
            else if (ac == "getdagx")
            {
                if (null != context.Request.QueryString["pid"])
                {
                    string pid = context.Request.QueryString["pid"];
                    getDagx(context, pid);
                }

            }
               

        }

        public void getDagx(HttpContext context,string pid)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                LCrs.Model.PersonInfo p = bll.GetModel(int.Parse(pid));
                
                string strJson = "[{\"drelation\":\"" + p.drelation + "\",\"hrelation\":\"" + p.hrelation + "\",\"sbrelation\":\"" + p.sbrelation + "\"}]";


                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();

            }
        }

        public void outUser(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string sname, sno, sbir, ebir, workname, workarea, sex, ftype, nation, eduschool, fstatus, sinputtime, einputtime, outreason, soutday, eoutday, political, education;
                sname = sno = sbir = ebir = workname = workarea = sex = ftype = nation = eduschool = fstatus = sinputtime = einputtime = outreason = soutday = eoutday = political = education = "";
                string filedOrder = "";
                if (null != context.Request.Form["hselectname"])
                {
                    filedOrder = context.Request.Form["hselectname"].ToString().Trim();
                }
                if (null != context.Request.Form["hsname"])
                {
                    sname = context.Request.Form["hsname"].ToString().Trim();
                }
                if (null != context.Request.Form["hsno"])
                {
                    sno = context.Request.Form["hsno"].ToString().Trim();
                }
                if (null != context.Request.Form["hsbir"])
                {
                    sbir = context.Request.Form["hsbir"].ToString().Trim();
                }
                if (null != context.Request.Form["hebir"])
                {
                    ebir = context.Request.Form["hebir"].ToString().Trim();
                }
                if (null != context.Request.Form["hworkname"])
                {
                    workname = context.Request.Form["hworkname"].ToString().Trim();
                }
                if (null != context.Request.Form["hworkarea"])
                {
                    workarea = context.Request.Form["hworkarea"].ToString().Trim();
                }
                if (null != context.Request.Form["hsex"])
                {
                    sex = context.Request.Form["hsex"].ToString().Trim();
                }
                if (null != context.Request.Form["hftype"])
                {
                    ftype = context.Request.Form["hftype"].ToString().Trim();
                }
                if (null != context.Request.Form["hnation"])
                {
                    nation = context.Request.Form["hnation"].ToString().Trim();
                }
                if (null != context.Request.Form["heduschool"])
                {
                    eduschool = context.Request.Form["heduschool"].ToString().Trim();
                }
                if (null != context.Request.Form["hfstatus"])
                {
                    fstatus = context.Request.Form["hfstatus"].ToString().Trim();
                }
                if (null != context.Request.Form["hsinputtime"])
                {
                    sinputtime = context.Request.Form["hsinputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["heinputtime"])
                {
                    einputtime = context.Request.Form["heinputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["houtreason"])
                {
                    outreason = context.Request.Form["houtreason"].ToString().Trim();
                }
                if (null != context.Request.Form["hsoutday"])
                {
                    soutday = context.Request.Form["hsoutday"].ToString().Trim();
                }
                if (null != context.Request.Form["heoutday"])
                {
                    eoutday = context.Request.Form["heoutday"].ToString().Trim();
                }
                if (null != context.Request.Form["hpolitical"])
                {
                    political = context.Request.Form["hpolitical"].ToString().Trim();
                }
                if (null != context.Request.Form["heducation"])
                {
                    education = context.Request.Form["heducation"].ToString().Trim();
                }                
                StringBuilder strWhere = new StringBuilder();
                if (sname != "")
                {
                    strWhere.AppendFormat(" pname like '%{0}%'  and ", sname);
                }
                if (sno != "")
                {
                    strWhere.AppendFormat("  id like '%{0}%' and", sno);
                }
                if (sbir != "")
                {
                    strWhere.AppendFormat("  birthday >= '{0}' and", sbir);
                }
                if (ebir != "")
                {
                    strWhere.AppendFormat("  birthday <= '{0}' and", ebir);
                }
                if (workname != "")
                {
                    strWhere.AppendFormat("  workname like '%{0}%' and", workname);
                }
                if (workarea != "")
                {
                    strWhere.AppendFormat("  workarea='{0}' and ", workarea);
                }
                if (sex != "")
                {
                    strWhere.AppendFormat("  sex='{0}' and", sex);
                }
                if (ftype != "")
                {
                    strWhere.AppendFormat("  ftype='{0}' and", ftype);
                }
                if (nation != "")
                {
                    strWhere.AppendFormat("  nation='{0}' and", nation);
                }
                if (eduschool != "")
                {
                    strWhere.AppendFormat("  eduschool like '%{0}%' and", eduschool);
                }
                if (fstatus != "")
                {
                    strWhere.AppendFormat("  fstatus='{0}' and", fstatus);
                }
                if (sinputtime != "")
                {
                    strWhere.AppendFormat("  inputtime>='{0}' and", sinputtime);
                }
                if (einputtime != "")
                {
                    strWhere.AppendFormat("  inputtime<='{0}' and", einputtime);
                }
                if (outreason != "")
                {
                    strWhere.AppendFormat("  outreason='{0}' and", outreason);
                }
                if (soutday != "")
                {
                    strWhere.AppendFormat("  outday>='{0}' and", soutday);
                }
                if (eoutday != "")
                {
                    strWhere.AppendFormat("  outday<='{0}' and", eoutday);
                }
                if (political != "")
                {
                    strWhere.AppendFormat("  political='{0}' and", political);
                }
                if (education != "")
                {
                    strWhere.AppendFormat("  education='{0}' and", education);
                }

                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }                

                //调用分页的GetList方法  
                DataSet ds = bll.GetList(0,strWhere.ToString(),filedOrder);
                string path = System.Web.HttpContext.Current.Server.MapPath("~");
                path = path.Substring(0, path.LastIndexOf("\\"));
                string outfile= @"\template\" + DateTime.Now.Ticks + ".xls";
                path += outfile;
                string strJson = "";
                bool isok=OutExcel.ExportToExcel(ds.Tables[0],path, ref strJson);
                if (isok)
                { 
                    strJson = outfile;
                    System.IO.FileInfo file = new System.IO.FileInfo(path);
                    context.Response.Clear();

                    context.Response.Charset = "utf-8";//设置输出的编码

                    context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                    // 添加头信息，为"文件下载/另存为"对话框指定默认文件名   

                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

                    // 添加头信息，指定文件大小，让浏览器能够显示下载进度   

                    context.Response.AddHeader("Content-Length", file.Length.ToString());

                    // 指定返回的是一个不能被客户端读取的流，必须被下载   

                    context.Response.ContentType = "application/msexcel";

                    // 把文件流发送到客户端   

                    context.Response.WriteFile(file.FullName);

                    context.Response.End();
                }
                else
                    strJson = "@@" + strJson;
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void importUser(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string result = "";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string savepath = "";
                HttpFileCollection files = context.Request.Files;
                if (files.Count == 1)
                {
                    HttpPostedFile file = files[0];
                    if (file.ContentLength > 0)
                    {
                        //全路径  
                        string FullFullName = file.FileName;
                        //获取图片的名称  
                        String fileName = FullFullName.Substring(FullFullName.LastIndexOf("\\") + 1);
                        string exp = fileName.Substring(fileName.LastIndexOf('.')).ToLower();
                        string filenames = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        string path = "~/uppics";
                        savepath = "/uppics";
                        if (exp == ".xls")
                        {
                            file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + filenames + exp);
                            savepath += "/" + filenames + exp;
                        }
                        else
                        {
                            result = "模版文件类型不对！";                           

                        }
                        result=ImportXlsToData(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + filenames + exp);
                        MyTools.WriteLog("导出人员档案" , Web.Admin.myinfo.getID(context), context);

                    }
                }               
                
            }
            else
            {
                result="请重新登录！";
            }
            context.Response.Write(result);//返回给前台页面  
            context.Response.End();

        }
        private string ImportXlsToData(string fileName)
        {
            string result = "";
            try
            {
                if (fileName == string.Empty)
                {
                    throw new ArgumentNullException("Excel文件上传失败！");
                }
                string oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fileName + "; Extended Properties='Excel 8.0;IMEX=1'";
                OleDbConnection oleDBConn = null;
                OleDbDataAdapter oleAdMaster = null;
                DataTable m_tableName = new DataTable();
                DataSet ds = new DataSet();
                oleDBConn = new OleDbConnection(oleDBConnString);
                oleDBConn.Open();
                m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                if (m_tableName != null && m_tableName.Rows.Count > 0)
                {
                    m_tableName.TableName = "人员信息$";
                }
                string sqlMaster;
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "A:AZ]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "persone");
                m_tableName.TableName = "工作经历$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "work");
                m_tableName.TableName = "专业技术职务$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "technical");
                //
                m_tableName.TableName = "职业资格$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "job");

                m_tableName.TableName = "语言$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "language");
                m_tableName.TableName = "教育经历$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "edu");
                m_tableName.TableName = "家庭情况$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "family");
                m_tableName.TableName = "奖励情况$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "reward");
                m_tableName.TableName = "处分情况$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "punishment");
                m_tableName.TableName = "培训经历$";
                sqlMaster = " SELECT *  FROM [" + m_tableName.TableName + "]";
                oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
                oleAdMaster.Fill(ds, "train");                
                oleAdMaster.Dispose();
                // oleDBConn.Close();
                oleDBConn.Dispose();
                result = AddDatasetToSQL(ds, 10);
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
        }
        private DateTime? getDateTime(string dt)
        {
            DateTime  dtt ;
            if (dt != "")
            {
                if (dt.Length == 6)
                {
                    string year = dt.Substring(0, 4);
                    string yue = dt.Substring(4, 2);

                    if (int.Parse(yue) > 12)
                    {
                        yue = "12";
                    }

                    //dt = year + "-" + yue + "-" + "01";
                    dt = year + yue;

                    dtt = DateTime.ParseExact(dt, "yyyyMM", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces);

                    return dtt;
                }
                else if (dt.Length == 8)
                {
                    string year = dt.Substring(0, 4);
                    string yue = dt.Substring(4, 2);
                    string ri = dt.Substring(6, 2);

                    int yuei = int.Parse(yue);

                    if (yuei > 12)
                    {
                        yue = "12";
                    }

                    
                    //dt = year + "-" + yue + "-" + ri;
                    dt = year + yue + ri;
                    dtt = DateTime.ParseExact(dt, "yyyyMMdd", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces);
                    return dtt;
                }
                else
                {
                    return null;
                }
                
            }
            else
            {
                return null;
            }
            
        }
        private string  AddDatasetToSQL(DataSet pds, int Cols)
        {
            Model.PersonInfo model;
            BLL.workinfo bllw = new BLL.workinfo();
            Model.workinfo modelw;
            BLL.technicalinfo bllte = new BLL.technicalinfo();
                Model.technicalinfo modelte;
            BLL.jobinfo bllj = new BLL.jobinfo();
            Model.jobinfo modelj = new Model.jobinfo();
            BLL.languageinfo blll = new BLL.languageinfo();
            Model.languageinfo modell = new Model.languageinfo();
            BLL.eduinfo blle = new BLL.eduinfo();
            Model.eduinfo modele = new Model.eduinfo();
            BLL.familyinfo bllf = new BLL.familyinfo();
            Model.familyinfo modelf = new Model.familyinfo();
            BLL.rewardinfo bllr = new BLL.rewardinfo();
            Model.rewardinfo modelr = new Model.rewardinfo();
            BLL.punishmentinfo bllp = new BLL.punishmentinfo();
            Model.punishmentinfo modelp = new Model.punishmentinfo();
            BLL.traininfo bllt = new BLL.traininfo();
            Model.traininfo modelt = new Model.traininfo();
            string result = "";
            int ic, ir,count=0,pid=0;
            string br = "\n";
            ic = pds.Tables[0].Columns.Count;
            if (pds.Tables[0].Columns.Count < Cols)
            {
                throw new Exception("导入Excel格式错误！Excel只有" + ic.ToString() + "列");
            }
            //编号	姓名	身份证号	曾用名	出生日期	籍贯5	出生地	性别	民族	婚姻状况	
            ir = pds.Tables[0].Rows.Count;
            if (pds != null && pds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < pds.Tables[0].Rows.Count; i++)
                {
                    model =new Model.PersonInfo();
                    model.pname = pds.Tables[0].Rows[i][1].ToString().Trim();
                    int.TryParse(pds.Tables[0].Rows[i][0].ToString().Trim(), out pid);
                    if (model.pname.Trim() != "" && model.pname.Trim() != "姓名")
                    {                        
                        model.ID = pds.Tables[0].Rows[i][2].ToString().Trim();
                        model.zname = pds.Tables[0].Rows[i][3].ToString().Trim();
                        model.birthday = getDateTime(pds.Tables[0].Rows[i][4].ToString().Trim());                       
                        model.porigin = pds.Tables[0].Rows[i][5].ToString().Trim();
                        model.birthadd = pds.Tables[0].Rows[i][6].ToString().Trim();
                        model.sex = pds.Tables[0].Rows[i][7].ToString().Trim();
                        model.nation = pds.Tables[0].Rows[i][8].ToString().Trim();
                        model.marital = pds.Tables[0].Rows[i][9].ToString().Trim();
                        //健康状况10 政治面貌    参加工作年月 最高学位    最高学历 最高学历毕业时间    
                        model.health = pds.Tables[0].Rows[i][10].ToString().Trim();
                        model.political = pds.Tables[0].Rows[i][11].ToString().Trim();
                        model.workday = pds.Tables[0].Rows[i][12].ToString().Trim();
                        model.degree = pds.Tables[0].Rows[i][13].ToString().Trim();
                        model.education = pds.Tables[0].Rows[i][14].ToString().Trim();
                        model.eduday = getDateTime( pds.Tables[0].Rows[i][15].ToString().Trim());
                        //最高学历毕业学校16 最高学历专业名称    最高学历专业类别 工作单位名称  工作单位机构类型 
                        model.eduschool = pds.Tables[0].Rows[i][16].ToString().Trim();
                        model.edumajor = pds.Tables[0].Rows[i][17].ToString().Trim();
                        model.edumajortype = pds.Tables[0].Rows[i][18].ToString().Trim();
                        model.workname = pds.Tables[0].Rows[i][19].ToString().Trim();
                        model.workjgtype = pds.Tables[0].Rows[i][20].ToString().Trim();
                        //工作单位经济类型21    工作单位所属行业 工作职位类型  工作地点行政区划 户籍地址    户籍行政区划 
                        model.workjjtype = pds.Tables[0].Rows[i][21].ToString().Trim();
                        model.worktrade = pds.Tables[0].Rows[i][22].ToString().Trim();
                        model.workjobtype = pds.Tables[0].Rows[i][23].ToString().Trim();
                        model.workarea = pds.Tables[0].Rows[i][24].ToString().Trim();
                        model.hjadd = pds.Tables[0].Rows[i][25].ToString().Trim();
                        model.hjarea = pds.Tables[0].Rows[i][26].ToString().Trim();
                        //现居住地    邮编 手机  电子邮件 存档机构名称  存档单位机构代码 存档单位编号  
                        model.address = pds.Tables[0].Rows[i][27].ToString().Trim();
                        model.zip = pds.Tables[0].Rows[i][28].ToString().Trim();
                        model.phnoe = pds.Tables[0].Rows[i][29].ToString().Trim();
                        model.email = pds.Tables[0].Rows[i][30].ToString().Trim();
                        model.filename = pds.Tables[0].Rows[i][31].ToString().Trim();
                        model.fnamecode = pds.Tables[0].Rows[i][32].ToString().Trim();
                        model.fnamebh = pds.Tables[0].Rows[i][33].ToString().Trim();
                        //存档单位机构类型 存档单位经济类型    存档单位所属行业 存档地点行政区划    存档编号 索引号 
                        model.fjgtype = pds.Tables[0].Rows[i][34].ToString().Trim();
                        model.fjjtype = pds.Tables[0].Rows[i][35].ToString().Trim();
                        model.ftrade = pds.Tables[0].Rows[i][36].ToString().Trim();
                        model.farea = pds.Tables[0].Rows[i][37].ToString().Trim();
                        model.fbh = pds.Tables[0].Rows[i][38].ToString().Trim();
                        model.findex = pds.Tables[0].Rows[i][39].ToString().Trim();
                        //存档状态 存档性质    存档管理机构名称 转入日期    转入原因 原存档单位名称 原存档地点行政区划 
                        model.fstatus = pds.Tables[0].Rows[i][40].ToString().Trim();
                        model.ftype = pds.Tables[0].Rows[i][41].ToString().Trim();
                        model.inday =getDateTime( pds.Tables[0].Rows[i][42].ToString().Trim());
                        model.inreason = pds.Tables[0].Rows[i][43].ToString().Trim();
                        model.oldname = pds.Tables[0].Rows[i][44].ToString().Trim();
                        model.oldarea = pds.Tables[0].Rows[i][45].ToString().Trim();
                        //转出日期    转出原因 转往单位名称  轩往单位行政区划

                        model.outday =getDateTime( pds.Tables[0].Rows[i][46].ToString().Trim());
                        model.outreason = pds.Tables[0].Rows[i][47].ToString().Trim();
                        model.newname = pds.Tables[0].Rows[i][48].ToString().Trim();
                        model.newarea = pds.Tables[0].Rows[i][49].ToString().Trim();
                        try
                        {
                            int num = bll.Add(model);
                            if (num == 0)
                            {
                                result += "导入未成功！" + model.pname + br;
                            }
                            else {
                                DateTime dt = DateTime.Now;
                                DataRow[] rows = pds.Tables["work"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelw = new Model.workinfo();
                                    modelw.sdate= getDateTime(rows[j][1].ToString().Trim());
                                    modelw.edate = getDateTime(rows[j][2].ToString().Trim());
                                    modelw.wname = rows[j][3].ToString().Trim();
                                    modelw.wjob = rows[j][4].ToString().Trim();
                                    modelw.zmname = rows[j][5].ToString().Trim();
                                    modelw.pid = num;
                                    modelw.inputtime = dt;
                                    bllw.Add(modelw);
                                }
                                rows = pds.Tables["technical"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelte = new Model.technicalinfo();
                                    modelte.tname = rows[j][1].ToString().Trim();
                                    modelte.tlevel = rows[j][2].ToString().Trim();                                    
                                    modelte.tdate =getDateTime(rows[j][3].ToString().Trim());                                    
                                    modelte.pid = num;
                                    modelte.inputtime = dt;
                                    bllte.Add(modelte);
                                }
                                rows = pds.Tables["job"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelj = new Model.jobinfo();
                                    modelj.jname = rows[j][1].ToString().Trim();
                                    modelj.jlevel = rows[j][2].ToString().Trim();                                   
                                    modelj.jdate = getDateTime(rows[j][3].ToString().Trim());
                                    modelj.pid = num;
                                    modelj.inputtime = dt;
                                    bllj.Add(modelj);
                                }
                                
                                rows = pds.Tables["language"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modell = new Model.languageinfo();
                                    modell.lname = rows[j][1].ToString().Trim();
                                    modell.llevel = rows[j][2].ToString().Trim();                                    
                                    modell.pid = num;
                                    modell.inputtime = dt;
                                    blll.Add(modell);
                                }

                                rows = pds.Tables["edu"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modele = new Model.eduinfo();
                                    modele.sdate= getDateTime(rows[j][1].ToString().Trim()); 
                                    modele.edate = getDateTime(rows[j][2].ToString().Trim());
                                    modele.eschool = rows[j][3].ToString().Trim();
                                    modele.edumajor = rows[j][4].ToString().Trim();
                                    modele.edudegree = rows[j][5].ToString().Trim();
                                    modele.education = rows[j][6].ToString().Trim();
                                    modele.edutype = rows[j][7].ToString().Trim();
                                    modele.stutype = rows[j][8].ToString().Trim();                                   
                                    modele.pid = num;
                                    modele.inputtime = dt;
                                    blle.Add(modele);
                                }
                                rows = pds.Tables["family"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelf = new Model.familyinfo();
                                    modelf.fname = rows[j][1].ToString().Trim();
                                    modelf.frelation = rows[j][2].ToString().Trim();
                                    modelf.fwork = rows[j][3].ToString().Trim();                                    
                                    modelf.pid = num;
                                    modelf.inputtime = dt;
                                    bllf.Add(modelf);
                                }
                                
                                rows = pds.Tables["reward"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelr = new Model.rewardinfo();
                                    modelr.rname = rows[j][1].ToString().Trim();
                                    modelr.rdw = rows[j][2].ToString().Trim();
                                    modelr.rdate =getDateTime(rows[j][3].ToString().Trim());
                                    modelr.pid = num;
                                    modelr.inputtime = dt;
                                    bllr.Add(modelr);
                                }
                                
                                rows = pds.Tables["punishment"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelp = new Model.punishmentinfo();
                                    modelp.pname = rows[j][1].ToString().Trim();
                                    modelp.pdw = rows[j][2].ToString().Trim();
                                    modelp.pdate = getDateTime(rows[j][3].ToString().Trim());
                                    modelp.pid = num;
                                    modelp.inputtime = dt;
                                    bllp.Add(modelp);
                                }
                                
                                    rows = pds.Tables["train"].Select("人员编号=" + pid);
                                for (int j = 0; j < rows.Length; j++)
                                {
                                    modelt = new Model.traininfo();
                                    modelt.sdate = getDateTime(rows[j][1].ToString().Trim());
                                    modelt.edate = getDateTime(rows[j][2].ToString().Trim());
                                    modelt.tname = rows[j][3].ToString().Trim();
                                    modelt.tzbdw = rows[j][4].ToString().Trim();                                    
                                    modelt.pid = num;
                                    modelt.inputtime = dt;
                                    bllt.Add(modelt);
                                }
                                count++;
                            }

                        }
                        catch (Exception ex)
                        {
                            result+= "导入未出错！" + model.pname+",问题："+ex.Message+br;
                        }
                    }
                }
                result += "成功导入" + count + "条记录" + br;
            }
            else
            {
                throw new Exception("导入数据为空！");
            }
            return result;
        }
        public void deletes(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string uidstr = context.Request.QueryString["uids"];
                if (bll.DeleteList(uidstr))
                {
                    MyTools.WriteLog("删除人员档案" + uidstr, Web.Admin.myinfo.getID(context), context);

                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }        
        public void delete(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = 0;
                string uidstr = context.Request.QueryString["uid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);

                //LCrs.BLL.userinfo bll = new LCrs.BLL.userinfo();
                if (bll.Delete(uid))
                {
                    MyTools.WriteLog("删除人员档案" + uid, Web.Admin.myinfo.getID(context), context);

                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }

        public void modify(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                int uid = 0;
                string uidstr = context.Request.Form["pid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);
                string pname = context.Request.Form["pname"];
                string ID = context.Request.Form["ID"];
                DateTime birthday = DateTime.Parse(context.Request.Form["birthday"]);
                string zname = context.Request.Form["zname"];
                string porigin = context.Request.Form["porigin"];
                string birthadd = context.Request.Form["birthadd"];
                string sex = context.Request.Form["sex"];
                string nation = context.Request.Form["nation"];
                string marital = context.Request.Form["marital"];
                string health = context.Request.Form["health"];
                string political = context.Request.Form["political"];
                string workday = context.Request.Form["workday"];
                string degree = context.Request.Form["degree"];
                string education = context.Request.Form["education"];
                DateTime eduday = DateTime.Parse(context.Request.Form["eduday"]);
                string eduschool = context.Request.Form["eduschool"];
                string edumajor = context.Request.Form["edumajor"];
                string edumajortype = context.Request.Form["edumajortype"];
                string workname = context.Request.Form["workname"];
                string workjgtype = context.Request.Form["workjgtype"];
                string workjjtype = context.Request.Form["workjjtype"];
                string worktrade = context.Request.Form["worktrade"];
                string workjobtype = context.Request.Form["workjobtype"];
                string workarea = context.Request.Form["workarea"];
                string hjadd = context.Request.Form["hjadd"];
                string hjarea = context.Request.Form["hjarea"];
                string address = context.Request.Form["address"];
                string zip = context.Request.Form["zip"];
                string phnoe = context.Request.Form["phnoe"];
                string email = context.Request.Form["email"];
                string filename = context.Request.Form["filename"];
                string fnamecode = context.Request.Form["fnamecode"];
                string fnamebh = context.Request.Form["fnamebh"];
                string fjgtype = context.Request.Form["fjgtype"];
                string fjjtype = context.Request.Form["fjjtype"];
                string ftrade = context.Request.Form["ftrade"];
                string farea = context.Request.Form["farea"];
                string fbh = context.Request.Form["fbh"];
                string findex = context.Request.Form["findex"];
                string fstatus = context.Request.Form["fstatus"];
                string ftype = context.Request.Form["ftype"];
                string fmanagername = context.Request.Form["fmanagername"];
                DateTime inday = DateTime.Parse(context.Request.Form["inday"]);
                string inreason = context.Request.Form["inreason"];
                string oldname = context.Request.Form["oldname"];
                string oldarea = context.Request.Form["oldarea"];
                DateTime outday = DateTime.Parse(context.Request.Form["outday"]);
                string outreason = context.Request.Form["outreason"];
                string newname = context.Request.Form["newname"];
                string newarea = context.Request.Form["newarea"];
                string remark = context.Request.Form["remark"];                

                LCrs.Model.PersonInfo model = new LCrs.Model.PersonInfo();
                model.pname = pname;
                model.ID = ID;
                model.birthday = birthday;
                model.zname = zname;
                model.porigin = porigin;
                model.birthadd = birthadd;
                model.sex = sex;
                model.nation = nation;
                model.marital = marital;
                model.health = health;
                model.political = political;
                model.workday = workday;
                model.degree = degree;
                model.education = education;
                model.eduday = eduday;
                model.eduschool = eduschool;
                model.edumajor = edumajor;
                model.edumajortype = edumajortype;
                model.workname = workname;
                model.workjgtype = workjgtype;
                model.workjjtype = workjjtype;
                model.worktrade = worktrade;
                model.workjobtype = workjobtype;
                model.workarea = workarea;
                model.hjadd = hjadd;
                model.hjarea = hjarea;
                model.address = address;
                model.zip = zip;
                model.phnoe = phnoe;
                model.email = email;
                model.filename = filename;
                model.fnamecode = fnamecode;
                model.fnamebh = fnamebh;
                model.fjgtype = fjgtype;
                model.fjjtype = fjjtype;
                model.ftrade = ftrade;
                model.farea = farea;
                model.fbh = fbh;
                model.findex = findex;
                model.fstatus = fstatus;
                model.ftype = ftype;
                model.fmanagername = fmanagername;
                model.inday = inday;
                model.inreason = inreason;
                model.oldname = oldname;
                model.oldarea = oldarea;
                model.outday = outday;
                model.outreason = outreason;
                model.newname = newname;
                model.newarea = newarea;               
                model.status = 0;
                model.remark = remark;
                model.pid = uid;               
                if (bll.Update(model))
                {
                    MyTools.WriteLog("修改人员档案" + model.pname, Web.Admin.myinfo.getID(context), context);

                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }

        public void modifygx(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                int pid = 0;
                string pidstr = context.Request.QueryString["pid"];
                if (pidstr != "")
                    pid = int.Parse(pidstr);
                string dr = context.Request.QueryString["dr"];
                string hr = context.Request.QueryString["hr"];
                string sr = context.Request.QueryString["sr"];

                LCrs.BLL.PersonInfo pb = new BLL.PersonInfo();

                LCrs.Model.PersonInfo model = new LCrs.Model.PersonInfo();
                model.pid = pid;
                model.drelation = int.Parse(dr);
                model.hrelation = int.Parse(hr);
                model.sbrelation = int.Parse(sr);

                if (bll.UpdateDHS(model))
                {
                    MyTools.WriteLog("修改人员档案关系" + model.pname, Web.Admin.myinfo.getID(context), context);

                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }

        public void add(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string pname = context.Request.Form["pname"];
                string ID = context.Request.Form["ID"];
                DateTime birthday = DateTime.Parse(context.Request.Form["birthday"]);
                string zname = context.Request.Form["zname"];
                string porigin = context.Request.Form["porigin"];
                string birthadd = context.Request.Form["birthadd"];
                string sex = context.Request.Form["sex"];
                string nation = context.Request.Form["nation"];
                string marital = context.Request.Form["marital"];
                string health = context.Request.Form["health"];
                string political = context.Request.Form["political"];
                string workday = context.Request.Form["workday"];
                string degree = context.Request.Form["degree"];
                string education = context.Request.Form["education"];
                DateTime eduday = DateTime.Parse(context.Request.Form["eduday"]);
                string eduschool = context.Request.Form["eduschool"];
                string edumajor = context.Request.Form["edumajor"];
                string edumajortype = context.Request.Form["edumajortype"];
                string workname = context.Request.Form["workname"];
                string workjgtype = context.Request.Form["workjgtype"];
                string workjjtype = context.Request.Form["workjjtype"];
                string worktrade = context.Request.Form["worktrade"];
                string workjobtype = context.Request.Form["workjobtype"];
                string workarea = context.Request.Form["workarea"];
                string hjadd = context.Request.Form["hjadd"];
                string hjarea = context.Request.Form["hjarea"];
                string address = context.Request.Form["address"];
                string zip = context.Request.Form["zip"];
                string phnoe = context.Request.Form["phnoe"];
                string email = context.Request.Form["email"];
                string filename = context.Request.Form["filename"];
                string fnamecode = context.Request.Form["fnamecode"];
                string fnamebh = context.Request.Form["fnamebh"];
                string fjgtype = context.Request.Form["fjgtype"];
                string fjjtype = context.Request.Form["fjjtype"];
                string ftrade = context.Request.Form["ftrade"];
                string farea = context.Request.Form["farea"];
                string fbh = context.Request.Form["fbh"];
                string findex = context.Request.Form["findex"];
                string fstatus = context.Request.Form["fstatus"];
                string ftype = context.Request.Form["ftype"];
                string fmanagername = context.Request.Form["fmanagername"];
                DateTime inday = DateTime.Parse(context.Request.Form["inday"]);
                string inreason = context.Request.Form["inreason"];
                string oldname = context.Request.Form["oldname"];
                string oldarea = context.Request.Form["oldarea"];

                DateTime ? outday = null;
                if (!string.IsNullOrEmpty(context.Request.Form["outday"]))
                {
                    outday = DateTime.Parse(context.Request.Form["outday"]);
                }

               
                string outreason = context.Request.Form["outreason"];
                string newname = context.Request.Form["newname"];
                string newarea = context.Request.Form["newarea"];                
                string remark = context.Request.Form["remark"];
                DateTime inputtime = DateTime.Now;

                LCrs.Model.PersonInfo model = new LCrs.Model.PersonInfo();
                model.pname = pname;
                model.ID = ID;
                model.birthday = birthday;
                model.zname = zname;
                model.porigin = porigin;
                model.birthadd = birthadd;
                model.sex = sex;
                model.nation = nation;
                model.marital = marital;
                model.health = health;
                model.political = political;
                model.workday = workday;
                model.degree = degree;
                model.education = education;
                model.eduday = eduday;
                model.eduschool = eduschool;
                model.edumajor = edumajor;
                model.edumajortype = edumajortype;
                model.workname = workname;
                model.workjgtype = workjgtype;
                model.workjjtype = workjjtype;
                model.worktrade = worktrade;
                model.workjobtype = workjobtype;
                model.workarea = workarea;
                model.hjadd = hjadd;
                model.hjarea = hjarea;
                model.address = address;
                model.zip = zip;
                model.phnoe = phnoe;
                model.email = email;
                model.filename = filename;
                model.fnamecode = fnamecode;
                model.fnamebh = fnamebh;
                model.fjgtype = fjgtype;
                model.fjjtype = fjjtype;
                model.ftrade = ftrade;
                model.farea = farea;
                model.fbh = fbh;
                model.findex = findex;
                model.fstatus = fstatus;
                model.ftype = ftype;
                model.fmanagername = fmanagername;
                model.inday = inday;
                model.inreason = inreason;
                model.oldname = oldname;
                model.oldarea = oldarea;
                if (outday != null)
                {
                    model.outday = outday;
                }             
                model.outreason = outreason;
                model.newname = newname;
                model.newarea = newarea;
                //model.drelation = drelation;
                //model.hrelation = hrelation;
                //model.sbrelation = sbrelation;
                model.status = 0;
                model.remark = remark;
                model.inputtime = inputtime;
                
                int rid=bll.Add(model);
                if (rid > 0)
                {
                    MyTools.WriteLog("增加人员档案" + model.pname, Web.Admin.myinfo.getID(context), context);                 
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
       
        public void Query(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string uname, utruename, st;
                uname = utruename = st = "";
                if (null != context.Request.Form["search_type"])
                {//获取前台传来的值  
                    st = context.Request.Form["search_type"].ToString().Trim();
                }
                if (null != context.Request.Form["search_value"])
                {//获取前台传来的值  
                    uname = context.Request.Form["search_value"].ToString().Trim();
                }
                if (st == "username")
                {
                    utruename = uname;
                    uname = "";
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" ID like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" pname like '%{0}%' and ", utruename);
                }

                strWhere.Append(" status = 0 and ");//未转出0、已转出 1.
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void QueryOne(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string uname, utruename, st;
                uname = utruename = st = "";
                if (null != context.Request.QueryString["pid"])
                {//获取前台传来的值  
                    st = context.Request.QueryString["pid"].ToString().Trim();
                }                
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                
                strWhere.AppendFormat(" pid={0} ", st);
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void Querys(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string sname, sno, sbir, ebir, workname, workarea, sex, ftype, nation, eduschool, fstatus, sinputtime, einputtime, outreason, soutday, eoutday, political, education;
                sname = sno = sbir = ebir= workname= workarea= sex= ftype= nation= eduschool= fstatus= sinputtime= einputtime = outreason= soutday= eoutday= political= education="";
                if (null != context.Request.Form["sname"])
                {
                    sname = context.Request.Form["sname"].ToString().Trim();
                }
                if (null != context.Request.Form["sno"])
                {
                    sno = context.Request.Form["sno"].ToString().Trim();
                }
                if (null != context.Request.Form["sbir"])
                {
                    sbir = context.Request.Form["sbir"].ToString().Trim();
                }
                if (null != context.Request.Form["ebir"])
                {
                    ebir = context.Request.Form["ebir"].ToString().Trim();
                }
                if (null != context.Request.Form["workname"])
                {
                    workname = context.Request.Form["workname"].ToString().Trim();
                }
                if (null != context.Request.Form["workarea"])
                {
                    workarea = context.Request.Form["workarea"].ToString().Trim();
                }
                if (null != context.Request.Form["sex"])
                {
                    sex = context.Request.Form["sex"].ToString().Trim();
                }
                if (null != context.Request.Form["ftype"])
                {
                    ftype = context.Request.Form["ftype"].ToString().Trim();
                }
                if (null != context.Request.Form["nation"])
                {
                    nation = context.Request.Form["nation"].ToString().Trim();
                }
                if (null != context.Request.Form["eduschool"])
                {
                    eduschool = context.Request.Form["eduschool"].ToString().Trim();
                }
                if (null != context.Request.Form["fstatus"])
                {
                    fstatus = context.Request.Form["fstatus"].ToString().Trim();
                }
                if (null != context.Request.Form["sinputtime"])
                {
                    sinputtime = context.Request.Form["sinputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["einputtime"])
                {
                    einputtime = context.Request.Form["einputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["outreason"])
                {
                    outreason = context.Request.Form["outreason"].ToString().Trim();
                }
                if (null != context.Request.Form["soutday"])
                {
                    soutday = context.Request.Form["soutday"].ToString().Trim();
                }
                if (null != context.Request.Form["eoutday"])
                {
                    eoutday = context.Request.Form["eoutday"].ToString().Trim();
                }
                if (null != context.Request.Form["political"])
                {
                    political = context.Request.Form["political"].ToString().Trim();
                }
                if (null != context.Request.Form["education"])
                {
                    education = context.Request.Form["education"].ToString().Trim();
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (sname != "")
                {
                    strWhere.AppendFormat(" pname like '%{0}%'  and ", sname);
                }
                if (sno != "")
                {
                    strWhere.AppendFormat("  id like '%{0}%' and", sno);
                }
                if (sbir != "")
                {
                    strWhere.AppendFormat("  birthday >= '{0}' and", sbir);
                }
                if (ebir != "")
                {
                    strWhere.AppendFormat("  birthday <= '{0}' and", ebir);
                }
                if (workname != "")
                {
                    strWhere.AppendFormat("  workname like '%{0}%' and", workname);
                }
                if (workarea != "")
                {
                    strWhere.AppendFormat("  workarea='{0}' and ", workarea);
                }
                if (sex != "")
                {
                    strWhere.AppendFormat("  sex='{0}' and", sex);
                }
                if (ftype != "")
                {
                    strWhere.AppendFormat("  ftype='{0}' and", ftype);
                }
                if (nation != "")
                {
                    strWhere.AppendFormat("  nation='{0}' and", nation);
                }
                if (eduschool != "")
                {
                    strWhere.AppendFormat("  eduschool like '%{0}%' and", eduschool);
                }
                if (fstatus != "")
                {
                    strWhere.AppendFormat("  fstatus='{0}' and", fstatus);
                }
                if (sinputtime != "")
                {
                    strWhere.AppendFormat("  inputtime>='{0}' and", sinputtime);
                }
                if (einputtime != "")
                {
                    strWhere.AppendFormat("  inputtime<='{0}' and", einputtime);
                }
                if (outreason != "")
                {
                    strWhere.AppendFormat("  outreason='{0}' and", outreason);
                }
                if (soutday != "")
                {
                    strWhere.AppendFormat("  outday>='{0}' and", soutday);
                }
                if (eoutday != "")
                {
                    strWhere.AppendFormat("  outday<='{0}' and", eoutday);
                }
                if (political != "")
                {
                    strWhere.AppendFormat("  political='{0}' and", political);
                }
                if (education != "")
                {
                    strWhere.AppendFormat("  education='{0}' and", education);
                }
                
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void Querysl(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string sname, sno, sbir, ebir, workname, inreason, workarea, sex, ftype, nation, eduschool, fstatus, sinputtime, einputtime, outreason, soutday, eoutday, political, education;
                inreason=sname = sno = sbir = ebir = workname = workarea = sex = ftype = nation = eduschool = fstatus = sinputtime = einputtime = outreason = soutday = eoutday = political = education = "";
                if (null != context.Request.Form["sname"])
                {
                    sname = context.Request.Form["sname"].ToString().Trim();
                }
                if (null != context.Request.Form["sno"])
                {
                    sno = context.Request.Form["sno"].ToString().Trim();
                }
                if (null != context.Request.Form["sbir"])
                {
                    sbir = context.Request.Form["sbir"].ToString().Trim();
                }
                if (null != context.Request.Form["ebir"])
                {
                    ebir = context.Request.Form["ebir"].ToString().Trim();
                }
                if (null != context.Request.Form["workname"])
                {
                    workname = context.Request.Form["workname"].ToString().Trim();
                }
                if (null != context.Request.Form["workarea"])
                {
                    workarea = context.Request.Form["workarea"].ToString().Trim();
                }
                if (null != context.Request.Form["sex"])
                {
                    sex = context.Request.Form["sex"].ToString().Trim();
                }
                if (null != context.Request.Form["ftype"])
                {
                    ftype = context.Request.Form["ftype"].ToString().Trim();
                }
                if (null != context.Request.Form["nation"])
                {
                    nation = context.Request.Form["nation"].ToString().Trim();
                }
                if (null != context.Request.Form["eduschool"])
                {
                    eduschool = context.Request.Form["eduschool"].ToString().Trim();
                }
                if (null != context.Request.Form["fstatus"])
                {
                    fstatus = context.Request.Form["fstatus"].ToString().Trim();
                }
                if (null != context.Request.Form["sinputtime"])
                {
                    sinputtime = context.Request.Form["sinputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["einputtime"])
                {
                    einputtime = context.Request.Form["einputtime"].ToString().Trim();
                }
                if (null != context.Request.Form["outreason"])
                {
                    outreason = context.Request.Form["outreason"].ToString().Trim();
                }
                if (null != context.Request.Form["soutday"])
                {
                    soutday = context.Request.Form["soutday"].ToString().Trim();
                }
                if (null != context.Request.Form["eoutday"])
                {
                    eoutday = context.Request.Form["eoutday"].ToString().Trim();
                }
                if (null != context.Request.Form["political"])
                {
                    political = context.Request.Form["political"].ToString().Trim();
                }
                if (null != context.Request.Form["education"])
                {
                    education = context.Request.Form["education"].ToString().Trim();
                }
                
                    if (null != context.Request.Form["inreason"])
                {
                    education = context.Request.Form["inreason"].ToString().Trim();
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (sname != "")
                {
                    strWhere.AppendFormat(" pname like '%{0}%'  and ", sname);
                }
                if (sno != "")
                {
                    strWhere.AppendFormat("  id like '%{0}%' and", sno);
                }
                if (sbir != "")
                {
                    strWhere.AppendFormat("  birthday >= '{0}' and", sbir);
                }
                if (ebir != "")
                {
                    strWhere.AppendFormat("  birthday <= '{0}' and", ebir);
                }
                if (workname != "")
                {
                    strWhere.AppendFormat("  workname like '%{0}%' and", workname);
                }
                if (workarea != "")
                {
                    strWhere.AppendFormat("  workarea='{0}' and ", workarea);
                }
                if (sex != "")
                {
                    strWhere.AppendFormat("  sex='{0}' and", sex);
                }
                if (ftype != "")
                {
                    strWhere.AppendFormat("  ftype='{0}' and", ftype);
                }
                if (nation != "")
                {
                    strWhere.AppendFormat("  nation='{0}' and", nation);
                }
                if (eduschool != "")
                {
                    strWhere.AppendFormat("  eduschool like '%{0}%' and", eduschool);
                }
                if (fstatus != "")
                {
                    strWhere.AppendFormat("  fstatus='{0}' and", fstatus);
                }
                if (sinputtime != "")
                {
                    strWhere.AppendFormat("  inputtime>='{0}' and", sinputtime);
                }
                if (einputtime != "")
                {
                    strWhere.AppendFormat("  inputtime<='{0}' and", einputtime);
                }
                if (outreason != "")
                {
                    strWhere.AppendFormat("  outreason='{0}' and", outreason);
                }
                if (inreason != "")
                {
                    strWhere.AppendFormat("  inreason='{0}' and", inreason);
                }
                if (soutday != "")
                {
                    strWhere.AppendFormat("  outday>='{0}' and", soutday);
                }
                if (eoutday != "")
                {
                    strWhere.AppendFormat("  outday<='{0}' and", eoutday);
                }
                if (political != "")
                {
                    strWhere.AppendFormat("  political='{0}' and", political);
                }
                if (education != "")
                {
                    strWhere.AppendFormat("  education='{0}' and", education);
                }

                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage("pid,fbh,pname,sex,birthday,education,eduschool,workname,edumajortype,phnoe,ftype", strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }

        public void outFP(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
               
                StringBuilder strWhere = new StringBuilder();

                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }

                LCrs.BLL.PersonListInfo pim = new BLL.PersonListInfo();


                //调用分页的GetList方法  
                DataSet ds = pim.GetList(0, strWhere.ToString(), "pldate desc");

                DataTable dt = new DataTable("");
                DataColumn dc = null;
                dc = dt.Columns.Add("档案目录", Type.GetType("System.String"));
                dc = dt.Columns.Add("类号", Type.GetType("System.String"));
                dc = dt.Columns.Add("材料目录", Type.GetType("System.String"));
                dc = dt.Columns.Add("制成时间", Type.GetType("System.String"));
                dc = dt.Columns.Add("份数", Type.GetType("System.String"));
                dc = dt.Columns.Add("页数", Type.GetType("System.String"));
                dc = dt.Columns.Add("备注", Type.GetType("System.String"));

                foreach (DataRow r in ds.Tables[0].Rows)
                {
                    DataRow nr;
                    nr = dt.NewRow();
                    nr["档案目录"] = r["plid"].ToString();
                    nr["类号"] = r["plno"].ToString();
                    nr["材料目录"] = r["plname"].ToString();
                    nr["制成时间"] = r["pldate"].ToString();
                    nr["份数"] = r["copynum"].ToString();
                    nr["页数"] = r["pagenum"].ToString();
                    nr["备注"] = r["plmark"].ToString();

                    dt.Rows.Add(nr);

                }


                string path = System.Web.HttpContext.Current.Server.MapPath("~");
                path = path.Substring(0, path.LastIndexOf("\\"));
                string outfile = @"\template\" + DateTime.Now.Ticks + ".xls";
                path += outfile;
                string strJson = "";
                bool isok = OutExcel.ExportToExcel(dt, path, ref strJson);
                if (isok)
                {
                    strJson = outfile;
                    System.IO.FileInfo file = new System.IO.FileInfo(path);
                    context.Response.Clear();

                    context.Response.Charset = "utf-8";//设置输出的编码

                    context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                    // 添加头信息，为"文件下载/另存为"对话框指定默认文件名   

                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

                    // 添加头信息，指定文件大小，让浏览器能够显示下载进度   

                    context.Response.AddHeader("Content-Length", file.Length.ToString());

                    // 指定返回的是一个不能被客户端读取的流，必须被下载   

                    context.Response.ContentType = "application/msexcel";

                    // 把文件流发送到客户端   

                    context.Response.WriteFile(file.FullName);

                    context.Response.End();
                }
                else
                    strJson = "@@" + strJson;
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}